package service;

import com.baoai.dto.ArticleDto;
import com.baoai.service.IndexService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.IOException;

/**
 * Created by Administrator on 2017/5/9 0009.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring-mvc.xml"})
public class AddOrUpdateService {

    @Autowired
    private IndexService indexService;

    @Test
    public void testAdd(){

        ArticleDto articleDto = new ArticleDto();
        articleDto.setClassName("article");
        articleDto.setArticleId("319");
        articleDto.setTitle("生活是一段一段的");
        articleDto.setSrcJson("[\"http://192.168.8.242:8081/attachment/kindeditor/2017/05/20170509152107302344.png?_d=1494314472861\"]");
        articleDto.setAuthor("[\"小玲\"]");
        articleDto.setLabelIdJson("[2,3]");
        articleDto.setLabelJson("[\"恋爱\",\"相处法则\"]");
        articleDto.setCoverType("1");
//        articleDto.setVisitorNumber("");
        articleDto.setChannelId("1");
        articleDto.setChannelName("挽回爱情");
        articleDto.setSex("0");
        articleDto.setCreateDate(1494314484703L);
        articleDto.setUpdateDate(1494314484722L);
        articleDto.setRecommend("0");
//        articleDto.setState("1");
//        articleDto.setShareNumber("0");
//        articleDto.setPraiseNumber("0");
//        articleDto.setCollectNumber("0");
//        articleDto.setCommentNumber("0");
//        articleDto.setTutorId("0");

        try {
            indexService.saveOrUpdate(articleDto);
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    @Test
    public void query(){
        try {
            System.out.println(indexService.queryCommonList("生活", "article", null,null,1,10, "1"));

            System.out.println(indexService.queryList());
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void query1(){
        try {
            System.out.println(indexService.queryCommonList("吸引", "course", null,null,1,10, "1"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
